﻿#region

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogicLayer;

#endregion

namespace FastTrackCabService.CustomerPanel
{
    public partial class Notification : Page
    {
        private static List<BusinessObjects.Booking> _bookings = new List<BusinessObjects.Booking>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDataGridView();
            }
        }

        private void LoadDataGridView()
        {
            _bookings =
                BookingBLL.GetNofification(Convert.ToInt32(User.Identity.Name))
                    .OrderByDescending(item => item.OriginDateTime)
                    .ToList();
            dgvNotification.DataSource = _bookings;
            dgvNotification.DataBind();
        }

        protected void gvDrivers_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            dgvNotification.PageIndex = e.NewPageIndex;
        }

        protected void dgvNotification_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Seen"))
            {
                BookingBLL.ClearNofification(Convert.ToInt32(e.CommandArgument));
            }
            LoadDataGridView();
        }
    }
}